import { userAction } from '@/interface/store/reducers';
import { userlog } from '@/interface/user';
import { dayjsTime } from '@/utils/dayjs';

const initState = {
    user: {},
    userLog: '',
};

const user = (prevState = initState, action: userAction) => {
    //获取个人信息
    switch (action.type) {
        case 'user/getUserInfo':
            return {
                ...prevState,
                user: action.payload,
            };
        case 'user/getUserLog':
            return {
                ...prevState,
                userLog: action.payload.map((item: userlog) => {
                    item.key = item.id;
                    item.time = dayjsTime(item.time);
                    return item;
                }),
            };
        default:
            return prevState;
    }
};

export default user;
